#!/usr/bin/env python

from getpass import getpass
from sys import argv,exit
from fgs.proxy.interface.ssh import FgsSSHPasswordFile

if len(argv) != 3 and len(argv) != 4:
    print "Syntax: %s <password file> <user name> [<password>]"
    exit(1)

passwd_file = argv[1]
username = argv[2]

if len(argv) == 4:
    passwd = argv[3]
else:
    passwd = getpass("Password: ")
    passwd_check = getpass("Repeat password: ")
    if passwd != passwd_check:
        print "Passwords do not match."
        exit(1)

p = FgsSSHPasswordFile()
p.change_password(passwd_file, username, passwd)

print "Operation successful."
